package com.jiuzhe.commercial.view;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jiuzhe.commercial.R;


public class CustomProgressDialog extends Dialog {
    private Context context = null;
    private static CustomProgressDialog customProgressDialog = null;

    public CustomProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public CustomProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public static CustomProgressDialog createDialog(Context context) {
        customProgressDialog = new CustomProgressDialog(context, R.style.EasyListDialogStyle);
        customProgressDialog.setContentView(R.layout.dialog);
        customProgressDialog.setCanceledOnTouchOutside(false);
        customProgressDialog.show();
        Window window = customProgressDialog.getWindow();
        window.getAttributes().gravity = Gravity.CENTER;
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = context.getResources().getDisplayMetrics().widthPixels/5*4;
        window.setAttributes(lp);
        return customProgressDialog;
    }



    /**
     * [Summary]
     * setTitile 标题
     *
     * @param strTitle
     * @return
     */
    public CustomProgressDialog setTitile(String strTitle) {
        TextView tvTitle = (TextView) customProgressDialog.findViewById(R.id.tv_title);
        if (strTitle != null) {
            tvTitle.setText(strTitle);
        }else {
            tvTitle.setVisibility(View.GONE); //layout_marginTop
        }
        return customProgressDialog;
    }

    /**
     * [Summary]
     * setMessage 提示内容
     *
     * @param strMessage
     * @return
     */
    public CustomProgressDialog setMessage(String strMessage) {
        TextView tvMsg = (TextView) customProgressDialog.findViewById(R.id.tv_message);
       if (tvMsg != null) {
            tvMsg.setText(strMessage);
        }
        return customProgressDialog;
    }



    /**
     * 和activity的onDestroy()方法同步
     */
    public void onDestroy() {
     if (customProgressDialog != null){
         customProgressDialog = null;
     }
    }
}